package com.tianqi.familymap.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
import com.orhanobut.logger.Logger
import com.tianqi.familymap.R
import com.tianqi.familymap.adapter.RecORWatchAdapter
import com.tianqi.familymap.base.BaseFragment

class FirstFragment : BaseFragment() {
    private lateinit var fgView:View
    private val mTablaFirst by lazy<TabLayout> {
        fgView.findViewById(R.id.tabla_first)
    }
    private val mViewpagerFirst by lazy<ViewPager> {
        fgView.findViewById(R.id.viewpager_first)
    }
    private val mlist = ArrayList<BaseFragment>()

    override fun initView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        fgView = inflater.inflate(
            R.layout.fragment_first, container, false
        )
        initData()
        return fgView
    }

    private fun initData(){
        val title = ArrayList<String>()
        title.add("关注")
        title.add("推荐")
        val informationFragment = InformationFragment()
        val recommendFragment = RecommendFragment()
        mlist.add(informationFragment)
        mlist.add(recommendFragment)
        mViewpagerFirst.adapter = RecORWatchAdapter(childFragmentManager,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT,mlist,title)
        mTablaFirst.setupWithViewPager(mViewpagerFirst)
        mViewpagerFirst.currentItem = 1
    }

    override fun setMenuVisibility(menuVisible: Boolean) {
        super.setMenuVisibility(menuVisible)
    }

    override fun onResume() {
        super.onResume()
    }
}